import "crvpuppet"

define at3_head($webaddr="", $roleid="") {
  if $AutoMode==true and $CloudCRV==true {
    $NFSServerClientMount=get_provider_attr($webaddr,$roleid,"NFSServerClientMount")
    $filesystemdomain=get_role_attr($webaddr,$roleid,"FILESYSTEM_DOMAIN")
    $CondorPassword=get_role_attr($webaddr,$roleid,"CondorPassword")
    
    $condor_allow_negotiator_extra=""
  }
  
  if ( $AutoMode == false ) or ( $AutoMode==true and $CloudCRV==true ) {

    package { "condor":
      ensure => installed,
    }

    file { "$NFSServerClientMount/condor":
      owner => "root",
      group => "root",
      ensure => directory,
      mode => 755,
    }
    
    file { "$NFSServerClientMount/condor/condor_config":
      owner => "root",
      group => "root",
      mode => 644,
      content => template("at3_head/condor_config.tpl"),
      require => File["$NFSServerClientMount/condor"],
    }

    file { "/etc/condor/condor_config":
      owner => "root",
      group => "root",
      ensure  => symlink,
      replace => true,
      require => File["$NFSServerClientMount/condor"],      
      target    => "$NFSServerClientMount/condor/condor_config",
    }

    file { "/etc/condor/condor_config.local":
      owner => "root",
      group => "root",
      mode => 644,
      content => template("at3_head/condor_config.local.tpl"),
    }

    exec { create_condorpassword:
      command => "condor_store_cred -c add -p $CondorPassword",
      require => File["/etc/condor/condor_config","/etc/condor/condor_config.local"],
      creates => "/var/condor_credentiald",
    }
    
    service { [ "condor"]:
      ensure => running,
      enable => true,
      hasstatus => true,
      hasrestart => true,
      require => [Package["condor"], Exec["create_condorpassword"]],
    }

  }

  if $AutoMode==true and $CloudCRV==true {
    set_role_attr($webaddr,$roleid,"CondorHeadAddr","$fqdn")    
    set_role_attr($webaddr,$roleid,"ProfileApplied","True")
  }
}

define at3_head_reverse($webaddr, $roleid) {
  set_role_attr($webaddr,$roleid,"ReverseProfileApplied","True")
}

